<?php
class YingApi {
	public $headers;
	public $state;
	public $location;
	public $Url;
	public $Data=array("code"=>-2,"error"=>"链接不正确！");
	public function check($url) {
		$this->headers=get_headers("http://mp.weixinbridge.com/mp/wapredirect?url=".$url);
		$this->Url=$url;
		if($this->headers) {
			$this->location=isset($this->headers[6])?$this->headers[6]:"";
			if($this->location&&$this->url_replace($this->headers[6])==$url) {
				$this->Data=array("code"=>200,"url"=>$url,"status"=>"微信访问正常！");
			}
		}
		return $this;
	}
	public function filter() {
		$data=parse_url($this->location);
		if($data&&isset($data['query'])&&$data['query']) {
			parse_str($data['query'],$parame);
			if($parame&&isset($parame['main_type'])) {
				switch($parame['main_type']) {
					case 1:
					$this->Data=array("code"=>201,"url"=>$this->Url,"status"=>"微信访问异常（非官方网页）！");
					break;
					case 2:
					$this->Data=array("code"=>202,"url"=>$this->Url,"status"=>"微信访问异常（已红报毒）！");
					break;
					case 5:
					$this->Data=array("code"=>203,"url"=>$this->Url,"status"=>"微信访问异常（提示复制打开）！");
					break;
					default:
					$this->Data=array("code"=>200,"url"=>$this->Url,"status"=>"微信访问正常！");
					break;
				}
			}
		}
	}
	private function url_replace($str) {
		return str_replace(array("Location:"," "),array(null,null),$str);
	}
}
$url=$_REQUEST["url"];//需要查询的链接
if(empty($url)) {
	Back(array("code"=>-1,"error"=>"参数不完整！"));
	die();
}
$Api=new YingApi();
$Api->check($url)->filter();
Back($Api->Data);
die();
function Back($array=array(),$types=false) {
	header('Content-type: application/json');
	echo json_encode($array,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}